package com.yllt4cloud.common.ddbase.containers;

import com.yllt4cloud.common.ddbase.domain.AuthorityMode;
import com.yllt4cloud.common.ddbase.domain.Clerk;
import com.yllt4cloud.common.ddbase.domain.ConfirmAuthority;
import com.yllt4cloud.common.ddbase.domain.Department;
import com.yllt4cloud.common.ddbase.result.DeptInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 用户角色权限容器
 */
public class UserRoleContainer {

    private static final Logger logger = LoggerFactory.getLogger(UserRoleContainer.class);


    private static UserRoleContainer userRoleContainer = null;

    //获取实例
    public static UserRoleContainer instance() {
        if (null == userRoleContainer) {
            synchronized (UserRoleContainer.class) {
                if (null == userRoleContainer) {
                    userRoleContainer = new UserRoleContainer();
                }
            }
        }
        return userRoleContainer;
    }


    //存放用户id，对应的 redis   key
    private ConcurrentHashMap<String, String> userRoleMap = new ConcurrentHashMap<String, String>();

    //保存 用户菜单权限权限，key 是用户id  ，value  是 redis 的key

    private ConcurrentHashMap<String, String> userMenuMap = new ConcurrentHashMap<String, String>();

    //根据url存储确认的权限信息
    private ConcurrentHashMap<String, ConfirmAuthority> urlConfirmAuthorityMap = new ConcurrentHashMap<String, ConfirmAuthority>();

    //不在表 base_authoritymode 中，在base_confirmauthority 表中的 确认权限信息
    private ConcurrentHashMap<String, ConfirmAuthority> urlNotInAuthoritymodeMap = new ConcurrentHashMap<String, ConfirmAuthority>();
    //部门树缓存,包含部门对应的员工信息
    private Map<String, List<DeptInfo>> cachedDeptTreeMap = new ConcurrentHashMap<String, List<DeptInfo>>();

    //单单 是 全部部门 保存变量
    private ConcurrentHashMap<String, Department> deptMap = new ConcurrentHashMap<String, Department>();


//根据url 存储 全部权限方式数据
    private ConcurrentHashMap<String, AuthorityMode> urlAuthorityModelMap = new ConcurrentHashMap<String, AuthorityMode>();

    //存放员工map
    private ConcurrentHashMap<String, Clerk> clerkMap = new ConcurrentHashMap<String, Clerk>();

    //被冻结的 员工id，商秘id
    private static ConcurrentHashMap<Integer,Integer> freezeClerkShangMiIdMap=new ConcurrentHashMap<Integer,Integer>();

    public static ConcurrentHashMap<Integer, Integer> getFreezeClerkShangMiIdMap() {
        return freezeClerkShangMiIdMap;
    }

    public static void setFreezeClerkShangMiIdMap(ConcurrentHashMap<Integer, Integer> freezeClerkShangMiIdMap) {
        UserRoleContainer.freezeClerkShangMiIdMap = freezeClerkShangMiIdMap;
    }


    public ConcurrentHashMap<String, String> getUserRoleMap() {
        return userRoleMap;
    }

    public void setUserRoleMap(ConcurrentHashMap<String, String> userRoleMap) {
        this.userRoleMap = userRoleMap;
    }

    public ConcurrentHashMap<String, ConfirmAuthority> getUrlConfirmAuthorityMap() {
        return urlConfirmAuthorityMap;
    }

    public void setUrlConfirmAuthorityMap(ConcurrentHashMap<String, ConfirmAuthority> urlConfirmAuthorityMap) {
        if(urlConfirmAuthorityMap!=null){
            this.urlConfirmAuthorityMap = urlConfirmAuthorityMap;
        }

    }

    public ConcurrentHashMap<String, String> getUserMenuMap() {
        return userMenuMap;
    }

    public void setUserMenuMap(ConcurrentHashMap<String, String> userMenuMap) {
        if(userMenuMap!=null){
            this.userMenuMap = userMenuMap;
        }

    }

    public Map<String, List<DeptInfo>> getCachedDeptTreeMap() {
        return cachedDeptTreeMap;
    }

    public void setCachedDeptTreeMap(Map<String, List<DeptInfo>> cachedDeptTreeMap) {
        if(cachedDeptTreeMap!=null){
            this.cachedDeptTreeMap = cachedDeptTreeMap;
        }

    }

    public ConcurrentHashMap<String, Department> getDeptMap() {
        return deptMap;
    }

    public void setDeptMap(ConcurrentHashMap<String, Department> deptMap) {
        if(deptMap!=null){
            this.deptMap = deptMap;
        }

    }


    public ConcurrentHashMap<String, AuthorityMode> getUrlAuthorityModelMap() {
        return urlAuthorityModelMap;
    }

    public void setUrlAuthorityModelMap(ConcurrentHashMap<String, AuthorityMode> urlAuthorityModelMap) {
        if(urlAuthorityModelMap!=null){
            this.urlAuthorityModelMap = urlAuthorityModelMap;
        }

    }

    public ConcurrentHashMap<String, Clerk> getClerkMap() {
        return clerkMap;
    }

    public void setClerkMap(ConcurrentHashMap<String, Clerk> clerkMap) {
        if(clerkMap!=null){
            this.clerkMap = clerkMap;
        }

    }

    public ConcurrentHashMap<String, ConfirmAuthority> getUrlNotInAuthoritymodeMap() {
        return urlNotInAuthoritymodeMap;
    }

    public void setUrlNotInAuthoritymodeMap(ConcurrentHashMap<String, ConfirmAuthority> urlNotInAuthoritymodeMap) {
        this.urlNotInAuthoritymodeMap = urlNotInAuthoritymodeMap;
    }
}
